package com.java.interfaceLearn;

/**
 * @author Lenl
 * @create 2021-05-31 16:00
 */
public class ComparableCircle extends Circle implements  CompareObject {

    public ComparableCircle(double radius){
        super(radius);
    }
    @Override
    public int compareTo(Object o) {
        if(this==o)
        return 0;
        if(o instanceof CompareObject){
            ComparableCircle c=(ComparableCircle)o;
            //错误的：return (int)(this.getRadius()-c.getRadius())
            if(this.getRadius()>c.getRadius()){
                return 1;
            }else if(this.getRadius()<c.getRadius()){
                return -1;
            }else return 0;
        }else{
            return 0;
            //throw new RuntimeException("传入类型不匹配")//可抛出异常
        }
    }
}
